package com.bw.produce.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bw.common.core.web.controller.BaseController;
import com.bw.common.core.web.domain.AjaxResult;
import com.bw.common.core.web.page.TableDataInfo;
import com.bw.produce.domain.Type;
import com.bw.produce.domain.dto.TypeDTO;
import com.bw.produce.domain.dto.TypeRequest;
import com.bw.produce.domain.vo.TypeVO;
import com.bw.produce.query.TypeQueryObject;
import com.bw.produce.service.ITypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lemon
 * @date 2024/11/14 22:26
 **/
@RestController
@RequestMapping("/type")
public class TypeController extends BaseController {

    @Autowired
    private ITypeService typeService;

    /**
     * 根据参数编号获取详细信息
     */
    @GetMapping("/{typeId}")
    public AjaxResult getInfo(@PathVariable Long typeId) {
        return success(typeService.getInfo(typeId));
    }

    /**
     * 获取品牌列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TypeQueryObject queryParams){
        startPage();
        List<TypeVO> list = typeService.selectTypeList(queryParams);
        return getDataTable(list);
    }


    /**
     * 新增品牌
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TypeRequest typeRequest) {
        typeService.saveOrUpdate(typeRequest);
        return toAjax(true);
    }

    /**
     * 修改品牌
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TypeRequest typeRequest) {
        typeService.saveOrUpdate(typeRequest);
        return toAjax(true);
    }

    /**
     * 删除品牌
     */
    @DeleteMapping("/{typeId}")
    public AjaxResult remove(@PathVariable Long typeId) {
        typeService.deleteTypeById(typeId);
        return toAjax(true);
    }

    /**
     * 根获取下拉框
     */
    @GetMapping("/typeWithProperty")
    public AjaxResult typeWithProperty() {
        return success(typeService.typeWithProperty());
    }

    /**
     * 获取品牌列表
     */
    @GetMapping("/allType")
    public AjaxResult allType(){
        return AjaxResult.success(typeService.allType());
    }
}
